package com.example.yls.demoa;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends AppCompatActivity {

    private Button btnDel;
    private List<Student> studentList = new ArrayList<Student>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initStudents();

        btnDel = findViewById(R.id.btn_del);
        btnDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

        StudentAdapter adapter = new StudentAdapter(MainActivity.this, R.layout.student_item, studentList);
        ListView listView = findViewById(R.id.lv_listview);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                Student student = studentList.get(position);
                Toast.makeText(MainActivity.this,student.getName(),Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void initStudents() {

        Student student1 = new Student("张三", 55,"公");
        studentList.add(student1);
        Student student2 = new Student("阿勒", 55,"母");
        studentList.add(student2);
        Student student3 = new Student("李四", 55,"公");
        studentList.add(student3);
        Student student4 = new Student("阿狸", 55,"母");
        studentList.add(student4);
        Student student5 = new Student("王武", 55,"公");
        studentList.add(student5);


    }

}
